# -*- coding: utf-8 -*-
# $Id: checkup.py 12 2008-02-10 08:26:55Z gkuznets $

# mpcheckup
# Copyright 2008, 2009 Grigoriy Kuznetsov (gkuznets@yandex.ru)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from PyQt4.QtCore import QTime

class Checkup(object):
    __instance = None # Naive singleton
    
    @classmethod
    def instance(self):
        if Checkup.__instance is None:
            Checkup.__instance = Checkup()
        return Checkup.__instance
    
    def __init__(self):
        #Checkup.__instance = self
        self.__checkup_no = -1
        self.problems_count = 6
        self.__start_times = [None, None]
  
    def batchCount(self):
        from core.batch import Batch
        return len(Batch.all())
    
    def checkup(self):
        return self.__checkup_no
    
    def nextCheckup(self):
        if self.__checkup_no < 1:
            self.__checkup_no += 1
            self.__start_times[self.__checkup_no] = QTime.currentTime()
            
    def startTimes(self):
        return self.__start_times
    
    def running(self):
        return self.__checkup_no != -1